package org.wanho.manager.dao.impl;

import org.wanho.jdbc.JdbcTemplate;
import org.wanho.manager.dao.UserDao;
import org.wanho.manager.entity.User;
import org.wanho.manager.mapper.UserMapper;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2023-04-23 14:27
 * Description：<描述>
 */
public class UserDaoImpl implements UserDao {

    private JdbcTemplate<User> jt = new JdbcTemplate<>();

    @Override
    public List<User> selectAll() {
        String sql = "select\n" +
                "    u.id,\n" +
                "    u.login_name,\n" +
                "    u.password,\n" +
                "    r.id rid,\n" +
                "    r.role_name\n" +
                "from t_user u\n" +
                "    left join t_user_role ur on u.id=ur.user_id\n" +
                "    left join t_role r on ur.role_id=r.id;";
        return jt.query(sql, new UserMapper());
    }
}
